package com.blueocean.care.management.Controller;

import com.blueocean.care.management.domain.CustomException;
import com.blueocean.care.management.domain.SysResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author			作者:            zwg.BlueOcean
 * @date       			创建时间：2018年4月17日  下午4:12:29
 * @version  		版本号：    1.0*
 * @parameter  	* 
 * @since  			* 
 * @return  			*
 * @description	 拦截所有异常
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
	private static final Logger log =  LoggerFactory.getLogger(GlobalExceptionHandler.class);
	@ExceptionHandler(Exception.class)
	public SysResult handlerException(Exception ex){
		log.error("请求异常："+ex.getMessage());
		if(ex instanceof CustomException){
			CustomException cex=(CustomException)ex;
			return SysResult.ERROR(cex.getCode(), cex.getMessage());
		}
		return SysResult.ERROR(10001,"非法的路由");
	}
	
	

}

